import Animal from "./Animal.js";
import CanvasMap from "./CanvasMap.js";

export default class AnimalV1 extends Animal{
    power: number=2000;
    color="#FF0000";
    get type(): string {
        return "animalv1";
    }
    breed(env: CanvasMap, x: number, y: number) {
        let child=new AnimalV1({x,y});
        this.power=Math.floor(this.power/2)
        child.power=this.power;
        return env.create(child,this);
    }
    move(env: CanvasMap, x: number, y: number): void {
        //什么也不用做！这个动物通过吃来移动
    }
    tryEat(env: CanvasMap, x: number, y: number) {
        let success= super.tryEat(env,x,y);
        if(success){
            env.animalMove(this.x,this.y,x,y);
        }else{
            let msg=`ID为${this.id}的新生物捕猎失败,原因：`
            let food=env.findAnimalByPoint(x,y);
            if(food){
                if(food.power>=this.power){
                    msg=msg+`食物过于强大，我方能量：${this.power}对方能量：${this.power}`

                }else{
                    // if(food.type=="base"){
                    //     env.killAnimalByPoint(x,y);
                    //     env.animalMove(this.x,this.y,x,y);
                    // }
                    console.log(this,food);
                    msg=msg+"程序员的水平不行,程序有问题"+
                    `，${typeof this.power}${typeof food.power}我方能量：${this.power}对方能量：${this.power},我在${this.x}，${this.y}；它在${food.x}，${food.y}`
                    
                }
            }else{
                msg=msg+`坐标${x},${y}上没有生物`
                let success=this.breed(env,x,y);
                if(!success){
                    console.log("生育失败");
                }
            }
            console.log(msg);
        }
       
        return false;
    }
}